package com.qms.qep.domain;

import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.qms.common.annotation.Excel;
import com.qms.common.core.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 维修任务对象 repair_task
 * 
 * @author RepairTask
 */
public class RepairTask extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 状态常量定义 */
    public static final Integer STATUS_PENDING = 1;    // 待处理
    public static final Integer STATUS_PROCESSING = 2; // 处理中
    public static final Integer STATUS_COMPLETED = 3;  // 已完成
    
    /** 状态文本 */
    public static final String STATUS_TEXT_PENDING = "待处理";
    public static final String STATUS_TEXT_PROCESSING = "处理中";
    public static final String STATUS_TEXT_COMPLETED = "已完成";

    /** 主键ID */
    private Integer id;

    /** 任务编号 */
    @Excel(name = "任务编号", sort = 0)
    private String taskCode;

    /** 不合格品记录ID */
    @Excel(name = "不合格品ID", sort = 1)
    private Integer nonconformingId;

    /** 产品ID */
    @Excel(name = "产品ID", sort = 2)
    private Integer productId;

    /** 产品名称 */
    @Excel(name = "产品名称", sort = 3)
    private String productName;
    
    /** 批次ID */
    @Excel(name = "批次ID", sort = 4)
    private Integer batchId;

    /** 批次编号 */
    @Excel(name = "批次编号", sort = 5)
    private String batchCode;
    
    /** 缺陷ID */
    @Excel(name = "缺陷ID", sort = 6)
    private Integer defectId;

    /** 缺陷名称 */
    @Excel(name = "缺陷名称", sort = 7)
    private String defectName;
    
    /** 不合格品描述 */
    @Excel(name = "缺陷描述", sort = 8)
    private String defectDescription;
    
    /** 维修项目 */
    @Excel(name = "维修项目", sort = 9)
    private String repairItem;

    /** 维修人员 */
    @Excel(name = "维修人员", sort = 10)
    private String repairPerson;

    /** 维修部门 */
    @Excel(name = "维修部门", sort = 11)
    private String repairDepartment;

    /** 维修方法 */
    @Excel(name = "维修方法", sort = 12)
    private String repairMethod;

    /** 维修人员 */
    @Excel(name = "维修人员", sort = 13)
    private String repairman;

    /** 维修日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "维修日期", width = 30, dateFormat = "yyyy-MM-dd", sort = 14)
    private Date repairDate;

    /** 维修结果 */
    @Excel(name = "维修结果", sort = 15)
    private String repairResult;

    /** 计划开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "计划开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", sort = 16)
    private Date planStartTime;

    /** 计划结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "计划结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", sort = 17)
    private Date planEndTime;

    /** 实际开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "实际开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", sort = 18)
    private Date actualStartTime;

    /** 实际结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "实际结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", sort = 19)
    private Date actualEndTime;

    /** 维修要求 */
    @Excel(name = "维修要求", sort = 20)
    private String repairRequirements;

    /** 状态（1待处理 2处理中 3已完成） */
    @Excel(name = "状态", readConverterExp = "1=待处理,2=处理中,3=已完成", sort = 21)
    private Integer status;
    
    /** 状态文本 - 用于前端展示 */
    @Excel(name = "状态", sort = 22)
    private transient String statusText;

    // 扩展字段
    /** 维修评价 */
    private String evaluationResult;

    public void setId(Integer id) 
    {
        this.id = id;
    }

    public Integer getId() 
    {
        return id;
    }

    public String getTaskCode() 
    {
        return taskCode;
    }

    public void setTaskCode(String taskCode) 
    {
        this.taskCode = taskCode;
    }

    public void setNonconformingId(Integer nonconformingId) 
    {
        this.nonconformingId = nonconformingId;
    }

    public Integer getNonconformingId() 
    {
        return nonconformingId;
    }
    public void setProductId(Integer productId) 
    {
        this.productId = productId;
    }

    public Integer getProductId() 
    {
        return productId;
    }
    public void setBatchId(Integer batchId) 
    {
        this.batchId = batchId;
    }

    public Integer getBatchId() 
    {
        return batchId;
    }
    public void setDefectId(Integer defectId) 
    {
        this.defectId = defectId;
    }

    public Integer getDefectId() 
    {
        return defectId;
    }

    public String getRepairItem() 
    {
        return repairItem;
    }

    public void setRepairItem(String repairItem) 
    {
        this.repairItem = repairItem;
    }

    public String getRepairPerson() 
    {
        return repairPerson;
    }

    public void setRepairPerson(String repairPerson) 
    {
        this.repairPerson = repairPerson;
    }

    public String getRepairDepartment() 
    {
        return repairDepartment;
    }

    public void setRepairDepartment(String repairDepartment) 
    {
        this.repairDepartment = repairDepartment;
    }

    public void setRepairMethod(String repairMethod) 
    {
        this.repairMethod = repairMethod;
    }

    public String getRepairMethod() 
    {
        return repairMethod;
    }
    public void setRepairman(String repairman) 
    {
        this.repairman = repairman;
    }

    public String getRepairman() 
    {
        return repairman;
    }
    public void setRepairDate(Date repairDate) 
    {
        this.repairDate = repairDate;
    }

    public Date getRepairDate() 
    {
        return repairDate;
    }
    public void setRepairResult(String repairResult) 
    {
        this.repairResult = repairResult;
    }

    public String getRepairResult() 
    {
        return repairResult;
    }

    public Date getPlanStartTime() 
    {
        return planStartTime;
    }

    public void setPlanStartTime(Date planStartTime) 
    {
        this.planStartTime = planStartTime;
    }

    public Date getPlanEndTime() 
    {
        return planEndTime;
    }

    public void setPlanEndTime(Date planEndTime) 
    {
        this.planEndTime = planEndTime;
    }

    public Date getActualStartTime() 
    {
        return actualStartTime;
    }

    public void setActualStartTime(Date actualStartTime) 
    {
        this.actualStartTime = actualStartTime;
    }

    public Date getActualEndTime() 
    {
        return actualEndTime;
    }

    public void setActualEndTime(Date actualEndTime) 
    {
        this.actualEndTime = actualEndTime;
    }

    public String getRepairRequirements() 
    {
        return repairRequirements;
    }

    public void setRepairRequirements(String repairRequirements) 
    {
        this.repairRequirements = repairRequirements;
    }

    public void setStatus(Integer status) 
    {
        this.status = status;
    }
    
    public void setStatus(String statusText) 
    {
        this.status = convertStatusTextToCode(statusText);
    }

    public Integer getStatus() 
    {
        return status;
    }
    
    public String getStatusText() 
    {
        if (statusText == null && status != null) {
            statusText = convertStatusCodeToText(status);
        }
        return statusText;
    }
    
    public void setStatusText(String statusText) 
    {
        this.statusText = statusText;
        // 同步更新status字段
        this.status = convertStatusTextToCode(statusText);
    }
    
    /**
     * 将状态文本转换为状态码
     */
    @JsonIgnore
    public static Integer convertStatusTextToCode(String statusText) 
    {
        if (STATUS_TEXT_PENDING.equals(statusText)) {
            return STATUS_PENDING;
        } else if (STATUS_TEXT_PROCESSING.equals(statusText)) {
            return STATUS_PROCESSING;
        } else if (STATUS_TEXT_COMPLETED.equals(statusText)) {
            return STATUS_COMPLETED;
        }
        // 默认为待处理
        return STATUS_PENDING;
    }
    
    /**
     * 将状态码转换为状态文本
     */
    @JsonIgnore
    public static String convertStatusCodeToText(Integer statusCode) 
    {
        if (STATUS_PENDING.equals(statusCode)) {
            return STATUS_TEXT_PENDING;
        } else if (STATUS_PROCESSING.equals(statusCode)) {
            return STATUS_TEXT_PROCESSING;
        } else if (STATUS_COMPLETED.equals(statusCode)) {
            return STATUS_TEXT_COMPLETED;
        }
        // 默认为待处理
        return STATUS_TEXT_PENDING;
    }
    
    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getBatchCode() {
        return batchCode;
    }

    public void setBatchCode(String batchCode) {
        this.batchCode = batchCode;
    }

    public String getDefectName() {
        return defectName;
    }

    public void setDefectName(String defectName) {
        this.defectName = defectName;
    }

    public String getDefectDescription() {
        return defectDescription;
    }

    public void setDefectDescription(String defectDescription) {
        this.defectDescription = defectDescription;
    }
    
    public String getEvaluationResult() {
        return evaluationResult;
    }

    public void setEvaluationResult(String evaluationResult) {
        this.evaluationResult = evaluationResult;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("taskCode", getTaskCode())
            .append("nonconformingId", getNonconformingId())
            .append("productId", getProductId())
            .append("batchId", getBatchId())
            .append("defectId", getDefectId())
            .append("repairItem", getRepairItem())
            .append("repairPerson", getRepairPerson())
            .append("repairDepartment", getRepairDepartment())
            .append("repairMethod", getRepairMethod())
            .append("repairman", getRepairman())
            .append("repairDate", getRepairDate())
            .append("repairResult", getRepairResult())
            .append("planStartTime", getPlanStartTime())
            .append("planEndTime", getPlanEndTime())
            .append("actualStartTime", getActualStartTime())
            .append("actualEndTime", getActualEndTime())
            .append("repairRequirements", getRepairRequirements())
            .append("status", getStatus())
            .append("createTime", getCreateTime())
            .append("updateTime", getUpdateTime())
            .append("remark", getRemark())
            .toString();
    }
} 